package com.tiantian.app.manager;

 

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferenceSetting {
	
	public static final String settingName = "tiantian";

	public static final String USERNAME = "username";
	public static final String PASSWORD = "password";
	public static final String PHONELANG = "phoneLang";
	
	public static final String REMEMBER_PASSWORD = "remember_passowrd";
	public static final String AUTO_LOGIN = "auto_login";
	
	
 
	public static SharedPreferenceSetting instance;
 
	static SharedPreferences setting;
 

	private SharedPreferenceSetting(SharedPreferences spf) {
		// TODO Auto-generated constructor stub
		setting = spf;
	}
	
	public static SharedPreferenceSetting getInstance(SharedPreferences spf){
		if(instance == null){
			instance = new SharedPreferenceSetting(spf);
		}
		return instance;
	}
	
 
 
	
 
	
	public static void setUserName(Context context,String userName){
		
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		SharedPreferences.Editor edit = setting.edit();
		edit.putString(USERNAME, userName);
		edit.commit();
	}
	
	public static String getUserName(Context context){
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		return setting.getString(USERNAME, "");
	}
	
	
	public static void setPassword(Context context,String password){
		
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		SharedPreferences.Editor edit = setting.edit();
		edit.putString(PASSWORD, password);
		edit.commit();
	}
	
	public static String getPassword(Context context){
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		return setting.getString(PASSWORD, "");
	}
	
	public static void setRememberPassword(Context context,boolean autoLogin){
		
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		SharedPreferences.Editor edit = setting.edit();
		edit.putBoolean(REMEMBER_PASSWORD, autoLogin);
		edit.commit();
	}
	
	public static boolean getRememberPassword(Context context){
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		return setting.getBoolean(REMEMBER_PASSWORD, false);
	}
	
	public static void setAutoLogin(Context context,boolean autoLogin){
		
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		SharedPreferences.Editor edit = setting.edit();
		edit.putBoolean(AUTO_LOGIN, autoLogin);
		edit.commit();
	}
	
	public static boolean getAutoLogin(Context context){
		if(setting == null){
			setting = context.getSharedPreferences(settingName, 0);
		}
		return setting.getBoolean(AUTO_LOGIN, false);
	}
	
 
	
	

}
